let initState = {
    list:[]
}

function cartReducer(state=initState,action){
    switch(action.type){
        case "ADD_GOODS":
            let newState = JSON.parse(JSON.stringify(state));
            newState.list.push(action.name);
            return newState;
        case "REMOVE_GOODS":
            let mystate = JSON.parse(JSON.stringify(state));
            mystate.list.splice(action.index,1);
            return mystate;
        case "SET_CARTLIST":
            let newStates = JSON.parse(JSON.stringify(state));
            newStates.list = action.list;
            return newStates
        default :
            return state;
    }
}


export default cartReducer;